<template>
  <div>
    <!-- 主内容区域 -->
    <div class="main-content">
      <div class="page-title">内容分析</div>
      <!-- 内容筛选 -->
      <div class="content-filters">
        <div class="filter-row">
          <el-form :inline="true" class="demo-form-inline">
          <el-form-item>
            <div
                class="list-search-one-right flex justify-between cursor-pointer"
                @click="toggleClass"
                :class="{ 'list-search-one-change': isSelected }"
            >
              <div class="flex items-center">
                <div class="right-time ml-1 w-20">发布日期</div>
                <div class="right-change">
                  <el-date-picker
                      v-model="dateRange"
                      type="datetimerange"
                      :picker-options="pickerOptions"
                      range-separator="至"
                      start-placeholder="开始日期"
                      end-placeholder="结束日期"
                      align="right"
                  >
                  </el-date-picker>
                </div>
              </div>
              <div class="mr-5">
                <i class="el-icon-date text-gray-400"></i>
              </div>
            </div>
          </el-form-item>
          <el-form-item class="list-search-three">
            <el-select v-model="contentType" placeholder="请选择内容类型">
              <template #prefix>
                <div class="ml-2">
                  <span>内容类型</span>
                  <el-divider direction="vertical"></el-divider>
                </div>
              </template>
              <el-option
                  v-for="item in sortingOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item class="list-search-three">
            <el-select v-model="category" placeholder="请选择内容分类">
              <template #prefix>
                <div class="ml-2">
                  <span>内容分类</span>
                  <el-divider direction="vertical"></el-divider>
                </div>
              </template>
              <el-option
                  v-for="item in categoryOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item class="list-search-three">
            <el-select v-model="status" placeholder="请选择内容状态">
              <template #prefix>
                <div class="ml-2">
                  <span>内容状态</span>
                  <el-divider direction="vertical"></el-divider>
                </div>
              </template>
              <el-option
                  v-for="item in statusOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-input
                v-model="keyword"
                placeholder="请输入关键词搜索"
                class="search-input-77 mr-3"
            >
              <template #prefix>
                <span>关键词</span>
                <el-divider direction="vertical"></el-divider>
              </template>
              <template #append>
              <el-button @click="searchContent">搜索</el-button>
            </template>
            </el-input>
          </el-form-item>
          <el-form-item class="list-search-three">
            <el-select v-model="sortBy" placeholder="请选择排序方式">
              <template #prefix>
                <div class="ml-2">
                  <span>排序方式</span>
                  <el-divider direction="vertical"></el-divider>
                </div>
              </template>
              <el-option
                  v-for="item in sortByOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <div class="filter-actions">
          <el-button @click="resetFilters">重置</el-button>
          <el-button type="primary" @click="searchContent">应用筛选</el-button>
        </div>
          </el-form-item>
        </el-form>
        </div>
      
      </div>
      <!-- 内容表现概览 -->
      <div class="content-overview">
        <div class="overview-header">
          <div class="overview-title">内容表现概览</div>
          <div class="overview-tabs">
            <div class="overview-tab active" @click="changeOverviewTab('all')">全部内容</div>
            <div class="overview-tab" @click="changeOverviewTab('top')">头部内容</div>
            <div class="overview-tab" @click="changeOverviewTab('middle')">中部内容</div>
            <div class="overview-tab" @click="changeOverviewTab('bottom')">底部内容</div>
          </div>
        </div>
        <div class="overview-metrics">
          <div class="metric-card">
            <div class="metric-title">平均曝光量</div>
            <div class="metric-value">{{ formatNumber(overviewData.avgViews) }}</div>
            <div class="metric-change positive">
              <i class="fa-solid fa-arrow-up"></i>
              <span>{{ overviewData.avgViewsChange }}%</span>
            </div>
          </div>
          <div class="metric-card">
            <div class="metric-title">平均互动量</div>
            <div class="metric-value">{{ formatNumber(overviewData.avgInteractions) }}</div>
            <div class="metric-change positive">
              <i class="fa-solid fa-arrow-up"></i>
              <span>{{ overviewData.avgInteractionsChange }}%</span>
            </div>
          </div>
          <div class="metric-card">
            <div class="metric-title">平均互动率</div>
            <div class="metric-value">{{ overviewData.avgInteractionRate }}%</div>
            <div class="metric-change negative">
              <i class="fa-solid fa-arrow-down"></i>
              <span>{{ overviewData.avgInteractionRateChange }}%</span>
            </div>
          </div>
          <div class="metric-card">
            <div class="metric-title">内容增长率</div>
            <div class="metric-value">{{ overviewData.contentGrowthRate }}%</div>
            <div class="metric-change positive">
              <i class="fa-solid fa-arrow-up"></i>
              <span>{{ overviewData.contentGrowthRateChange }}%</span>
            </div>
          </div>
        </div>
      </div>
      <!-- 内容分析图表 -->
      <div class="content-charts">
        <div class="chart-card">
          <div class="chart-title">内容类型表现对比</div>
          <div class="chart-container">
            <canvas id="contentTypeChart"></canvas>
          </div>
        </div>
        <div class="chart-card">
          <div class="chart-title">内容发布趋势</div>
          <div class="chart-container">
            <canvas id="publishTrendChart"></canvas>
          </div>
        </div>
        <div class="chart-card">
          <div class="chart-title">互动指标分布</div>
          <div class="chart-container">
            <canvas id="interactionDistributionChart"></canvas>
          </div>
        </div>
        <div class="chart-card">
          <div class="chart-title">不同时段发布效果</div>
          <div class="chart-container">
            <canvas id="timeSlotPerformanceChart"></canvas>
          </div>
        </div>
      </div>
      <!-- 内容列表 -->
      <div class="content-list">
        <div class="list-header">
          <div class="list-title">内容详细数据</div>
          <div class="content-actions">
            <el-button type="text" size="small" @click="exportData">
              <i class="fa-solid fa-download"></i> 导出数据
            </el-button>
            <el-button type="text" size="small" @click="refreshData">
              <i class="fa-solid fa-refresh"></i> 刷新
            </el-button>
          </div>
        </div>
        <el-table :data="contentList" stripe style="width: 100%">
          <el-table-column label="内容" width="300">
            <template #default="scope">
              <div class="content-title-cell">
                <img :src="scope.row.cover" alt="内容封面" class="content-cover">
                <span>{{ scope.row.title }}</span>
              </div>
            </template>
          </el-table-column>
          <!-- 因内容截断，后续表格列省略 -->
        </el-table>
      </div>
    </div>
  </div>
</template>

<script>
export default {
   name: "Content-View",
  data() {
    return {
      activeMenu: 'analytics-content',
      dateRange: [],
      contentType: '',
      category: '',
      status: '',
      keyword: '',
      sortBy: 'views_desc',
      overviewTab: 'all',
      overviewData: {
        avgViews: 0,
        avgViewsChange: 0,
        avgInteractions: 0,
        avgInteractionsChange: 0,
        avgInteractionRate: 0,
        avgInteractionRateChange: 0,
        contentGrowthRate: 0,
        contentGrowthRateChange: 0
      },
      contentList: [],
      isSelected: false,
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      sortByOptions: [
        {
          value: "选项1",
          label: "最新发布",
        },
        {
          value: "选项2",
          label: "最多浏览",
        },
        {
          value: "选项3",
          label: "最多点赞",
        },
        {
          value: "选项3",
          label: "最多评论",
        },
      ],
      statusOptions: [
        {
          value: "选项1",
          label: "最新发布",
        },
        {
          value: "选项2",
          label: "最多浏览",
        },
        {
          value: "选项3",
          label: "最多点赞",
        },
        {
          value: "选项3",
          label: "最多评论",
        },
      ],
      categoryOptions: [
        {
          value: "选项1",
          label: "最新发布",
        },
        {
          value: "选项2",
          label: "最多浏览",
        },
        {
          value: "选项3",
          label: "最多点赞",
        },
        {
          value: "选项3",
          label: "最多评论",
        },
      ],
      sortingOptions: [
        {
          value: "选项1",
          label: "最新发布",
        },
        {
          value: "选项2",
          label: "最多浏览",
        },
        {
          value: "选项3",
          label: "最多点赞",
        },
        {
          value: "选项3",
          label: "最多评论",
        },
      ],
    };
  },
  watch: {
    value2(newValue, oldValue) {
      if (newValue || oldValue) {
        this.isSelected = false;
      }
    },
  },
  methods: {
    toggleClass() {
      this.isSelected = !this.isSelected;
    },
    handleOpen() {
      // 处理菜单展开事件
    },
    handleClose() {
      // 处理菜单关闭事件
    },
    searchContent() {
      // 处理搜索内容事件
    },
    resetFilters() {
      this.dateRange = [];
      this.contentType = '';
      this.category = '';
      this.status = '';
      this.keyword = '';
      this.sortBy = 'views_desc';
    },
    changeOverviewTab(tab) {
      this.overviewTab = tab;
    },
    formatNumber(num) {
      return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
    },
    exportData() {
      // 处理导出数据事件
    },
    refreshData() {
      // 处理刷新数据事件
    }
  },
  mounted() {
    // 组件挂载后执行的逻辑
    // 可在这里初始化图表等操作
  }
};
</script>

<style lang="scss" scoped>

/* 内容分析相关样式 */
.content-filters {
  background-color: white;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.05);
  margin-bottom: 20px;
}

.filter-row {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 15px;
}

.filter-label {
  width: 80px;
  text-align: right;
}

.date-range-picker {
  width: 300px;
}

.content-type-filter,
.category-filter,
.status-filter {
  width: 200px;
}

.keyword-search {
  flex: 1;
}

.filter-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* 内容表现概览 */
.content-overview {
  background-color: white;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.05);
  margin-bottom: 20px;
}

.overview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.overview-title {
  font-size: 18px;
  font-weight: 500;
}

.overview-tabs {
  display: flex;
  gap: 10px;
}

.overview-tab {
  padding: 8px 16px;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.overview-tab.active {
  background-color: rgba(254, 44, 85, 0.1);
  color: var(--primary-color);
}

.overview-metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
}

.metric-card {
  background-color: #F8F8F8;
  border-radius: 12px;
  padding: 15px;
  transition: all 0.3s ease;
}

.metric-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 5px 15px rgba(0,0,0,0.05);
}

.metric-title {
  font-size: 14px;
  color: var(--gray-color);
  margin-bottom: 5px;
}

.metric-value {
  font-size: 24px;
  font-weight: bold;
  margin-bottom: 5px;
}

.metric-change {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 14px;
}

.metric-change.positive {
  color: var(--success-color);
}

.metric-change.negative {
  color: var(--primary-color);
}

/* 内容分析图表 */
.content-charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.chart-card {
  background-color: white;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.chart-title {
  font-size: 16px;
  font-weight: 500;
  margin-bottom: 16px;
}

.chart-container {
  height: 300px;
}

/* 内容列表 */
.content-list {
  background-color: white;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.list-title {
  font-size: 16px;
  font-weight: 500;
}

.content-actions {
  display: flex;
  gap: 10px;
}

.el-table__header th {
  background-color: #F8F8F8;
}

.content-cover {
  width: 60px;
  height: 60px;
  border-radius: 8px;
  object-fit: cover;
}

.content-title-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-tag {
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
}

.status-published {
  background-color: rgba(76, 217, 100, 0.1);
  color: #4CD964;
}

.status-draft {
  background-color: rgba(153, 153, 153, 0.1);
  color: #999999;
}

.status-scheduled {
  background-color: rgba(51, 153, 255, 0.1);
  color: #3399FF;
}

.status-hidden {
  background-color: rgba(255, 149, 0, 0.1);
  color: #FF9500;
}

.performance-badge {
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
}

.performance-excellent {
  background-color: rgba(76, 217, 100, 0.1);
  color: #4CD964;
}

.performance-good {
  background-color: rgba(51, 153, 255, 0.1);
  color: #3399FF;
}

.performance-average {
  background-color: rgba(153, 153, 153, 0.1);
  color: #999999;
}

.performance-poor {
  background-color: rgba(255, 149, 0, 0.1);
  color: #FF9500;
}
.list-search-one-right {
  width: 100%;
  height: 40px;
  border: #dddfe6 1px solid;
  border-radius: 10px;
  display: flex;
  align-items: center;
  padding-left: 10px;

  .right-time {
    color: #c0c4cc;
    height: 14px;
    padding-right: 10px;
    line-height: 14px;
    border-right: 1px solid #dddfe6;
  }

  ::v-deep .el-input__inner {
    -webkit-appearance: none;
    background-color: #ffffff00;
    background-image: none;
    border-radius: 10px;
    border: 1px solid #3b5cab00;
    box-sizing: border-box;
    color: #606266;
    display: inline-block;
    font-size: inherit;
    height: 25px;
    line-height: 30px;
    margin-top: -8px;
    outline: none;
    transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
    width: 100%;
  }

  ::v-deep .el-range-editor.is-active {
    border-color: rgba(233, 132, 25, 0);
  }

  ::v-deep .el-icon-time:before {
    width: 10px;
    content: "";
    color: #faebd700;
    /* background-color: aqua; */
  }
}

.list-search-one-change {
  border: 1px #e18634 solid;
}
.list-search-three {
  ::v-deep .el-input__prefix {
    left: 11px;
  }

  ::v-deep .el-input--prefix .el-input__inner {
    padding-left: 97px;
    border-radius: 10px;
  }

  ::v-deep .el-select > .el-input {
    display: block;
    width: 320px;

  }
}
</style>
